{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'faceset_token': '52ed3456d1211f0ec0387f413ef998aa',\n",
       " 'time_used': 184,\n",
       " 'face_count': 0,\n",
       " 'face_added': 0,\n",
       " 'request_id': '1603021460,101dc813-10a0-47bd-b46c-48a07231048b',\n",
       " 'outer_id': '20201018',\n",
       " 'failure_detail': []}"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "api_secret = \"Vr0PtRCw-ZFwYXTKVfi6aDNaSqlfunK3\"\n",
    "api_key = 'jRpCaZ34kqNYJ8Zppdc-yGGum_YkETov'\n",
    "\n",
    "# 1.FaceSet Create\n",
    "import requests,json\n",
    "\n",
    "display_name = \"人脸集合1018\" #自定义人脸集合的名字\n",
    "outer_id = \"20201018\" #自定义标识\n",
    "user_data = \"test\" #自定义用户信息\n",
    "\n",
    "CreateFace_Url = \"https://api-cn.faceplusplus.com/facepp/v3/faceset/create\" #调用URL\n",
    "payload = {\n",
    "    # 请求参数\n",
    "    'api_key': api_key,\n",
    "    'api_secret': api_secret,\n",
    "    'display_name':display_name,\n",
    "    'outer_id':outer_id,\n",
    "    'user_data':user_data\n",
    "}\n",
    "r = requests.post(CreateFace_Url, params=payload)\n",
    "r.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'faceset_token': '52ed3456d1211f0ec0387f413ef998aa',\n",
       " 'tags': '',\n",
       " 'time_used': 88,\n",
       " 'user_data': 'test',\n",
       " 'display_name': '人脸集合1018',\n",
       " 'face_tokens': [],\n",
       " 'face_count': 0,\n",
       " 'request_id': '1603021481,3c684d07-df58-4562-a0a2-9db192955f50',\n",
       " 'outer_id': '20201018'}"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 2.FaceSet GetDetail（获取人脸集合信息）\n",
    "GetDetail_Url = \"https://api-cn.faceplusplus.com/facepp/v3/faceset/getdetail\"\n",
    "payload = {\n",
    "    'api_key': api_key,\n",
    "    'api_secret': api_secret,\n",
    "    'outer_id':outer_id,\n",
    "}\n",
    "r = requests.post(GetDetail_Url,params=payload)\n",
    "r.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'faceset_token': '52ed3456d1211f0ec0387f413ef998aa',\n",
       " 'time_used': 593,\n",
       " 'face_count': 1,\n",
       " 'face_added': 1,\n",
       " 'request_id': '1603021568,e204cfa6-4891-482e-9740-396c6e96e05f',\n",
       " 'outer_id': '20201018',\n",
       " 'failure_detail': []}"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 3.FaceSet AddFace（增加人脸信息）\n",
    "AddFace_url = \" https://api-cn.faceplusplus.com/facepp/v3/faceset/addface\"\n",
    "\n",
    "payload = {\n",
    "    'api_key': api_key,\n",
    "    'api_secret': api_secret,\n",
    "    'faceset_token':'52ed3456d1211f0ec0387f413ef998aa',\n",
    "    'face_tokens':'1aff0090208b37e2f8de321a8e2e96c7', # detect里获取的\n",
    "}\n",
    "r = requests.post(AddFace_url,params=payload)\n",
    "r.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'faceset_token': '52ed3456d1211f0ec0387f413ef998aa',\n",
       " 'face_removed': 1,\n",
       " 'time_used': 187,\n",
       " 'face_count': 0,\n",
       " 'request_id': '1603021618,ac78d6eb-222b-480e-b7b0-7e59d50a547e',\n",
       " 'outer_id': '20201018',\n",
       " 'failure_detail': []}"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 4.FaceSet RemoveFace（移除人脸信息）\n",
    "RemoveFace_url = \" https://api-cn.faceplusplus.com/facepp/v3/faceset/removeface\"\n",
    "\n",
    "payload = {\n",
    "    'api_key': api_key,\n",
    "    'api_secret': api_secret,\n",
    "    'faceset_token':'52ed3456d1211f0ec0387f413ef998aa',\n",
    "    'face_tokens':'1aff0090208b37e2f8de321a8e2e96c7',\n",
    "}\n",
    "r = requests.post(RemoveFace_url,params=payload)\n",
    "r.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'faceset_token': '52ed3456d1211f0ec0387f413ef998aa',\n",
       " 'request_id': '1603021669,188edf69-945f-4026-a5dd-8b2d87392337',\n",
       " 'time_used': 77,\n",
       " 'outer_id': '20201018'}"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 5.FaceSet Update（更新人脸集合信息）\n",
    "Update_url = \"https://api-cn.faceplusplus.com/facepp/v3/faceset/update\"\n",
    "payload = {\n",
    "    'api_key': api_key,\n",
    "    'api_secret': api_secret,\n",
    "    'faceset_token':'52ed3456d1211f0ec0387f413ef998aa',\n",
    "    'user_data':\"Test.\",\n",
    "}\n",
    "r = requests.post(Update_url,params=payload)\n",
    "r.json()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'faces1': [{'face_rectangle': {'width': 824,\n",
       "    'top': 871,\n",
       "    'left': 1114,\n",
       "    'height': 824},\n",
       "   'face_token': '26cf8ddf1370a7131772b47f389d7e48'}],\n",
       " 'faces2': [{'face_rectangle': {'width': 86,\n",
       "    'top': 91,\n",
       "    'left': 65,\n",
       "    'height': 86},\n",
       "   'face_token': 'd74261adfc3a844832b36940470b1b8f'}],\n",
       " 'time_used': 2147,\n",
       " 'thresholds': {'1e-3': 62.327, '1e-5': 73.975, '1e-4': 69.101},\n",
       " 'confidence': 26.085,\n",
       " 'image_id2': 'g6kg8zfyOouG6ftP+GvEfg==',\n",
       " 'image_id1': 'KIOXEC2V/MyL4zuopAcNig==',\n",
       " 'request_id': '1603021704,6b7e272c-b979-4597-9db6-8d98e97a2371'}"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 6.Compare Face（对比人脸相似度）\n",
    "liudehua01 = \"https://gss0.baidu.com/9fo3dSag_xI4khGko9WTAnF6hhy/zhidao/pic/item/7c1ed21b0ef41bd57f7f20ff57da81cb39db3d89.jpg\"\n",
    "liudehua02 = \"https://tse3-mm.cn.bing.net/th/id/OIP.Xz3HbYZeNrdUnGJ7vXNzsQHaKO?pid=Api&rs=1\"\n",
    "wangzulan = \"https://tse3-mm.cn.bing.net/th/id/OIP.ZnXeGoVYT4jQudiPOGZn3QAAAA?pid=Api&rs=1\"\n",
    "\n",
    "Compare_url = \"https://api-cn.faceplusplus.com/facepp/v3/compare\"\n",
    "payload ={\n",
    "    'api_key': api_key,\n",
    "    'api_secret': api_secret,\n",
    "    'image_url1':liudehua01,\n",
    "    'image_url2':wangzulan\n",
    "}\n",
    "r = requests.post(Compare_url,params=payload)\n",
    "r.json()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.3"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
